package com.kdgc.springboot001;

import com.kdgc.springboot001.javabean.Pet;
import com.kdgc.springboot001.javabean.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@SpringBootApplication
public class  Springboot001Application {

    public static void main(String[] args) {
        ConfigurableApplicationContext run =
                SpringApplication.run(Springboot001Application.class, args);


        /*查看springboot为我们自动装配的组件*/
      /*  String[] beanDefinitionNames = run.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }*/


        /*向容器中 取出 自动以组件  默认是单例的*/
        Object user01 = run.getBean("user01");
        System.out.println(user01);

        Object user02 = run.getBean("user01");
        System.out.println(user02);


        //如果@Configuration(proxyBeanMethods = true)代理对象调用方法。SpringBoot总会检查这个组件是否在容器中有。
        //保持组件单实例

        User user03 = run.getBean("user01", User.class);
        Pet tom = run.getBean("tom", Pet.class);

        System.out.println("用户的宠物："+(user03.getPet() == tom));


        /*通过  importResources  导入的组件*/
        Pet hehe = run.getBean("hehe", Pet.class);
        System.out.println(hehe);


        //查看某一类型的 组件有没有
       /* WebMvcConfigurationSupport bean = run.getBean(WebMvcConfigurationSupport.class);
        System.out.println(bean);*/
    }

}
